<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">
            <el-form ref="formRef" :model="form" :rules="rules" label-width="100px" style="width:350px;margin-left:100px">
              <el-form-item label="用户名" prop="username">
                <el-input v-model="form.username"></el-input>
              </el-form-item>
              <el-form-item label="密码" prop="password">
                <el-input v-model="form.password"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" size="small" @click="submit">更新</el-button>
              </el-form-item>
            </el-form>

          </el-tab-pane>
          <el-tab-pane label="个人信息">
            <user-info></user-info>
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <job-info></job-info>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getEmplyeeBaseInfo } from '@/api/user'
import { saveUserDetailById } from '@/api/employees'
import userInfo from './components/user-info.vue'
import JobInfo from './components/job-info.vue'
export default {
  name: '',
  components: { userInfo, JobInfo },
  props: {
    id: {
      type: [String, Number],
      required: true
    }
  },
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, trigger: 'blur', message: '用户名不能为空' }
        ],
        password: [
          { required: true, trigger: 'blur', message: '密码不能为空' },
          { min: 6, max: 16, trigger: 'blur', message: '请输入6到16位密码' }]
      }
    }
  },
  computed: {

  },
  async created() {
    // 获取员工基本信息，回填表单
    this.form = await getEmplyeeBaseInfo(this.id)
    this.form.password = ''
  },
  methods: {
    // 更新密码
    submit() {
      this.$refs.formRef.validate(async isOk => {
        if (!isOk) return
        await saveUserDetailById(this.form)
        this.$message.success('操作成功')
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
